package com.xuxin.baby.utils;

import android.view.Gravity;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beloo.widget.chipslayoutmanager.ChipsLayoutManager;

/**
 * Created by xu_xin
 * Created on 2020.08.01 0001
 */
public class RecycleUtils {

    public static void init(RecyclerView view) {
        view.setLayoutManager(new LinearLayoutManager(view.getContext()));
        view.setItemViewCacheSize(20);
        view.setNestedScrollingEnabled(false);
    }

    public static void initNested(RecyclerView view) {
        view.setLayoutManager(new LinearLayoutManager(view.getContext()));
        view.setItemViewCacheSize(20);
        view.setNestedScrollingEnabled(true);
    }

    public static void init(RecyclerView view, int num) {
        view.setLayoutManager(new GridLayoutManager(view.getContext(), num));
        view.setItemViewCacheSize(20);
        view.setNestedScrollingEnabled(false);
    }

    public static void horizontal(RecyclerView view) {
        LinearLayoutManager manager = new LinearLayoutManager(view.getContext());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        view.setLayoutManager(manager);
        view.setItemViewCacheSize(20);
        view.setNestedScrollingEnabled(false);
    }

    public static void chips(RecyclerView view) {
        ChipsLayoutManager chipsLayoutManager = ChipsLayoutManager.newBuilder(view.getContext())
                .setChildGravity(Gravity.TOP)
                .setScrollingEnabled(false)
                .setMaxViewsInRow(5)
                .setGravityResolver(position -> {
                    return Gravity.CENTER;
                })
                .setOrientation(ChipsLayoutManager.HORIZONTAL)
                .setRowStrategy(ChipsLayoutManager.STRATEGY_DEFAULT)
                .withLastRow(true)
                .build();
        view.setLayoutManager(chipsLayoutManager);
        view.setItemViewCacheSize(10);
        view.setNestedScrollingEnabled(false);
    }
}